﻿<?php
require_once '../../include/common.inc.php';
if($cfg['config']['loginguest']=='0')header('location:../../logging.php');
require_once PPCHAT_ROOT.'./include/json.php';
$json=new JSON_obj;

//房间状态
if($cfg['config']['state']=='2' and $_SESSION['room_'.$cfg['config']['id']]!=true){header("location:../login.php?1");exit();}
if($cfg['config']['state']=='0'){exit("<script>location.href='../error.php?msg=系统处于关闭状态！请稍候……'</script>");exit();}

//用户信息
$uid=$_SESSION['login_uid'];
$db->query("update {$tablepre}members set regip='$onlineip' where uid='{$uid}'");
$userinfo=$db->fetch_row($db->query("select m.*,ms.* from {$tablepre}members m,{$tablepre}memberfields ms  where m.uid=ms.uid and m.uid='{$uid}'"));
$_SESSION['login_gid']=$userinfo['gid'];

//是否登录
//if(!isset($_SESSION['login_uid'])){
//if(!$_SESSION['login_uid']){
//    header("location:/room/m/minilogin.php");exit();
//	echo '<script>openWin(2,false,"minilogin.php",390,310)</script>';
//}

//是否登录
if (!$_SESSION['login_uid'] ) {
    header("location:/room/m/minilogin.php");exit();
}
//新人登录
if(!isset($_SESSION['login_uid']) and $cfg['config']['loginguest']=="1"){gusetLogin();}

//if($cfg['config']['allow_rpwd']){
//    $e = isset($_REQUEST['rpwd'])?1:0;
//
//    //没有密码参数就读取session
//    if(!$_REQUEST['rpwd']){
//        if( abs(time()-$_SESSION['last_access']) <= 60*60*2.5){
//            $_REQUEST['rpwd'] = $_SESSION['rpwd'];
//        }
//    }else {
//        $_SESSION['last_access'] = time();
//        $_SESSION['rpwd'] = $_REQUEST['rpwd'];
//    }
//    if($_REQUEST['rpwd'] !== $cfg['config']['rpwd'] ){
//        header("location:/room/m/pwdLogin.php?e=$e&rid=".$cfg['config']['id']);exit();
//    }
//}

$usergroup=$db->fetch_row($db->query("select * from {$tablepre}auth_group where id='{$userinfo['gid']}'"));


//if($cfg['config']['allow_rpwd']){
//    $e = isset($_REQUEST['rpwd'])?1:0;
//    if($_REQUEST['rpwd'] !== $cfg['config']['rpwd'] ){
//        header("location:/room/pwdLogin.php?e=$e&rid=".$cfg['config']['id']);exit();
//    }
//}

//新人
if($_SESSION['login_uid']==0){$userinfo['username']=$userinfo['nickname']=$_SESSION['login_nick'];$userinfo['sex']=$_SESSION['login_sex'];$userinfo['uid']=$_SESSION['login_guest_uid'];}

//黑名单
$query=$db->query("select * from {$tablepre}ban where (username='{$userinfo[username]}' or ip='{$onlineip}') and losttime>".gdate()." limit 1");
while($row=$db->fetch_row($query)){
    exit("<script>location.href='error.php?msg=用户名或IP受限！过期时间".date("Y-m-d H:i:s",$row['losttime'])."'</script>");exit();
}




//用户组
$query=$db->query("select * from {$tablepre}auth_group order by ov desc");
while($row=$db->fetch_row($query)){
    $groupli.="<div id='group_{$row[id]}'></div>";
    $grouparr.="grouparr['{$row[id]}']=".json_encode($row).";\n";
    $group["m".$row[id]]=$row;
}
//聊天历史记录
$query=$db->query("select * from {$tablepre}msgs where rid='".$cfg['config']['id']."' and p='false' and state!='1' and `type`='0' order by id desc limit 0,20 ");

while($row=$db->fetch_row($query)){
    $row['msg']=str_replace(array('&amp;', '','&quot;', '&lt;', '&gt;'), array('&', "\'",'"', '<', '>'),$row['msg']);


    //图片转换为空过滤规则
    $preg_str=preg_replace('/<img.*>/','',$row['msg']);

    //是否管理员
    $is_admin = strpos($group['m'.$userinfo['gid']]['rules'],'room_admin' );

    //屏蔽关键字
    if (preg_match ("/".$cfg['config']['msgban']."/", $preg_str, $m) && $is_admin === false )
    {
        continue;
    }

    $omsg.='<li class="chat-item">';
    $omsg.='<div class="message">';
    $omsg.='<span class="chat-tag-user-level icon-level-12"><img src="'.$group["m".$row[ugid]][ico].'" class="msg_group_ico" title="'.$grouptitle.'"></span>';
    $omsg.='<span class="chat-user-name">'.$row[uname].':</span>';
    $omsg.='<span class="chat-content">'.$row[msg].'</span>';
    $omsg.='</div>';
    $omsg.='</li>';


}

//获取最大ID
$query=$db->query("select max(id+0) max_id from {$tablepre}msgs");
$row=$db->fetch_row($query);

$_SESSION['max_msg_id']=$row['max_id'];
//其他处理
$ts=explode(':',$cfg['config']['tserver']);


if(!isset($_SESSION['room_'.$uid.'_'.$cfg['config'][id]])){
    $db->query("insert into  {$tablepre}msgs(rid,ugid,uid,uname,tuid,tname,mtime,ip,msg,`type`)values('{$cfg[config][id]}','{$userinfo[gid]}','{$userinfo[uid]}','{$userinfo[username]}','{$cfg[config][defvideo]}','{$cfg[config][defvideonick]}','".gdate()."','{$onlineip}','登陆直播间','3')");
    $db->query("update {$tablepre}memberfields set logins=logins+1 where uid='{$uid}'");
    $_SESSION['room_'.$uid.'_'.$cfg['config'][id]]=1;
}
?>

<!DOCTYPE html>
<html lang="zh-cmn-Hans" data-dpr="1" class="ios iphone mobile portrait"  >
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="renderer" content="webkit">
    <meta name="wap-font-scale" content="no">
    <meta name="format-detection" content="telephone=no" />
    <meta name="author" content="Pandaren">
    <meta name="hotcss" content="initial-dpr=1;max-width=640" />
    <meta name="viewport" content="width=device-width, initial-scale=1, minimum-scale=1, maximum-scale=1, user-scalable=no">
    <link rel="stylesheet" href="./css/pandacustom.css">
    <link rel="stylesheet" href="./css/panda1.css">
    <link rel="shortcut icon" type="image/x-icon" href="<?=$cfg['config']['ico']?>" />
    <script src="script/jquery.min.js"></script>
    <script src="script/layer.m-1.7.js"></script>
    <script src="script/main.m.js?<?=time()?>"></script>
        <script src="../script/device.min.js"></script>
<!--    <script src="script/socket.io.js"></script>-->
    <link href="css/webiaoqing.css" rel="stylesheet" type="text/css">
    <script src="script/webiaoqin.js" ></script>
    <script src="script/web_socket.js" type="text/javascript" charset="utf-8"></script>

    <script>
        var _hmt = _hmt || [];
        (function() {
            var hm = document.createElement("script");
            hm.src = "https://hm.baidu.com/hm.js?f04392890eb96a5574840f29ad7f02f9";
            var s = document.getElementsByTagName("script")[0];
            s.parentNode.insertBefore(hm, s);
        })();
    </script>

    <script>
        if (!device.mobile()){window.location = '../';}
        globalgid = <?=$cfg['config']['id']?>;
        des_msg = <?=$cfg['config']['des_msg']?>;
        is_login = <?=$_SESSION['login_uid']?>;

        var UserList;
        var ToUser;
        var VideoLoaded=false;
        var My={dm:'<?=$_SERVER['HTTP_HOST']?>',rid:'<?=$cfg['config']['id']?>',roomid:'<?=$cfg['config']['id']?>',chatid:'<?=$userinfo['uid']?>',name:'<?=$userinfo['username']?>',nick:'<?=$userinfo['nickname']?>',sex:'<?=$userinfo['sex']?>',age:'0',qx:'<?=check_auth('room_admin')?'1':'0'?>',ip:'<?=$onlineip?>',vip:'<?=$userinfo['gid']?>',color:'<?=$userinfo['gid']?>',cam:'0',state:'0',mood:'<?=$userinfo['mood']?>',rst:'<?=$time?>',camState:'1',key:'<?=connectkey()?>'}

        var RoomInfo={loginTip:'<?=$cfg['config']['logintip']?>',Msglog:'<?=$cfg['config']['msglog']?>',msgBlock:'<?=$cfg['config']['msgblock']?>',msgAudit:'<?=$cfg['config']['msgaudit']?>',defaultTitle:document.title,MaxVideo:'10',VServer:'<?=$cfg['config']['vserver']?>',VideoQ:'',TServer:'<?=$ts[0]?>',TSPort:'<?=$ts[1]?>',PVideo:'<?=$cfg['config']['defvideo']?>',AutoPublicVideo:'1',AutoSelfVideo:'0',type:'1',PVideoNick:'',OtherVideoAutoPlayer:'<?=$cfg['config']['livetype']?>',r:'<?=$cfg['config']['rebots']?>'}
        var grouparr=new Array();
        <?=$grouparr?>
        var ReLoad;
        var isIE=document.all;
        var aSex=['<span class="sex-womon"></span>','<span class="sex-man"></span>',''];
        var aColor=['#FFF','#FFF','#FFF'];
        var msg_unallowable="<?=$cfg['config']['msgban']?>";

    </script>

    <?php
    //禁言
    $query=$db->query("select * from {$tablepre}send where (username='{$userinfo[username]}' or ip='{$onlineip}') limit 1");
    while($row=$db->fetch_row($query)){
        echo "<script>remove_auth('msg_send');</script>";
    }
    ?>

  <script>
  (function(window, document) {
    'use strict';
    var hotcss = {};
    (function() {
      var viewportEl = document.querySelector('meta[name="viewport"]'),
        hotcssEl = document.querySelector('meta[name="hotcss"]'),
        dpr = window.devicePixelRatio || 1,
        maxWidth = 540,
        designWidth = 0;
      dpr = dpr >= 3 ? 3 : (dpr >= 2 ? 2 : 1);
      if (hotcssEl) {
        var hotcssCon = hotcssEl.getAttribute('content');
        if (hotcssCon) {
          var initialDprMatch = hotcssCon.match(/initial\-dpr=([\d\.]+)/);
          if (initialDprMatch) {
            dpr = parseFloat(initialDprMatch[1]);
          }
          var maxWidthMatch = hotcssCon.match(/max\-width=([\d\.]+)/);
          if (maxWidthMatch) {
            maxWidth = parseFloat(maxWidthMatch[1]);
          }
          var designWidthMatch = hotcssCon.match(/design\-width=([\d\.]+)/);
          if (designWidthMatch) {
            designWidth = parseFloat(designWidthMatch[1]);
          }
        }
      }
      document.documentElement.setAttribute('data-dpr', dpr);
      hotcss.dpr = dpr;
      document.documentElement.setAttribute('max-width', maxWidth);
      hotcss.maxWidth = maxWidth;
      if (designWidth) {
        document.documentElement.setAttribute('design-width', designWidth);
      }
      hotcss.designWidth = designWidth;
      var scale = 1 / dpr,
        content = 'width=device-width, initial-scale=' + scale + ', minimum-scale=' + scale + ', maximum-scale=' + scale + ', user-scalable=no';
      if (viewportEl) {
        viewportEl.setAttribute('content', content);
      } else {
        viewportEl = document.createElement('meta');
        viewportEl.setAttribute('name', 'viewport');
        viewportEl.setAttribute('content', content);
        document.head.appendChild(viewportEl);
      }
    })();
    hotcss.px2rem = function(px, designWidth) {
      if (!designWidth) {
        designWidth = parseInt(hotcss.designWidth, 10);
      }
      return parseInt(px, 10) * 320 / designWidth / 20;
    }
    hotcss.rem2px = function(rem, designWidth) {
      if (!designWidth) {
        designWidth = parseInt(hotcss.designWidth, 10);
      }
      return rem * 20 * designWidth / 320;
    }
    hotcss.mresize = function() {
      var innerWidth = document.documentElement.getBoundingClientRect().width || window.innerWidth;
      if (hotcss.maxWidth && (innerWidth / hotcss.dpr > hotcss.maxWidth)) {
        innerWidth = hotcss.maxWidth * hotcss.dpr;
      }
      if (!innerWidth) {
        return false;
      }
      document.documentElement.style.fontSize = (innerWidth * 20 / 320) + 'px';
      hotcss.callback && hotcss.callback();
    };
    hotcss.mresize();
    window.addEventListener('resize', function() {
      clearTimeout(hotcss.tid);
      hotcss.tid = setTimeout(hotcss.mresize, 33);
    }, false);
    window.addEventListener('load', hotcss.mresize, false);
    setTimeout(function() {
      hotcss.mresize();
    }, 333)
    window.hotcss = hotcss;
  })(window, document);
  </script>

  <title><?=$cfg['config']['title']?></title>
  <link rel="stylesheet" href="./css/panda.css">
</head>
<style>
    .bodyer {
        position: relative;
        padding: 0rem;
        margin: 0rem;
        background-color: #888888;
        transition: top 1s;
        -moz-transition: top 1s;
        -webkit-transition: top 1s;
        -o-transition: top 1s;
    }
</style>
<body class="bodyer" style=" overflow:hidden; ">
  <div class="container">
    <!-- 播放器 start -->
    <div class="room-matrix">
      <div class="live-room" id="live-player">
          <div class="video-box">
              <div class="video-wrap">
                  <div class="bg-opacity"></div>
              </div>
              <div class="video-wrap" id="view-wrap-container">
                  <div id="video-status-container" class="video-status-container"></div>
                  <div class="video-win" id="video-win">
                  </div>
              </div>
          </div>
      </div>
    </div>
    <!-- 播放器 end -->
    <div class="main-content">
      <div class="tabs-cnt">
        <a href="javascript:;" class="tabs-list tabs-list-chat active" data-type="chat">
          <span>聊天</span>
        </a>
        <a href="javascript:;" class="tabs-list tabs-list-recommend" data-type="recommend">
              <?php
              if($_SESSION['login_uid']>0)
              {
                  echo " <a href='../../logging.php?act=mlogout'>退出登陆</a>";
              }else {
                  echo '<span id="loginBtn" onClick="location.href=\'../m/minilogin.php\'">注册/登陆</span>';
              }
              ?>
        </a>
      </div>


        <!-- 聊天 start -->
        <div id="chatList" class="main-con" style="overflow-y:scroll; width:100%; ">
            <div id="publicChat" class="chat-con ps-container ps-active-y" style="" data-ps-id="3caa938d-cc6e-a133-7b6c-3771c0edfed6">
                <ul>
                        <?php echo $omsg;?>
                </ul>

                <div style="height:2.00rem; "></div>
            </div>
        </div>

  <footer id="footer" class="footer">
    <div class="comment-con">
              <div class="cmt-phiz">
                <a class="smile" href="javascript:;">
                  <i class="phiz-icon "></i>
                </a>
              </div>
      <div class="cmt-input">
        <form action="" class="form">
          <div class="input">
<!--            <input  id="messageEditor"   class="chatIput" placeholder="输入聊天内容..."></input>-->
              <article style="font-size: 16px;height: 35px;padding-top:10px;" id="form_article" contenteditable="true" onkeydown="myInput.listen(this, event);"></article>
          </div>
          <div   id="sendBtn" class="btn-cmt-send"><span>发 表</span></div>
        </form>
      </div>
    </div>

      <div class="layer-content phiz-layer-con swiper-container-horizontal" >
          <div class="page_emotion box_swipe" id="page_emotion">
              <dl id="list_emotion" class="list_emotion pt_10"></dl><!-- 表情框 -->
              <dt><ol id="nav_emotion" class="nav_emotion"></ol></dt><!-- 分页提示点 -->
          </div>
          <script>
              $(function(){
                  var say = '说点什么...';
                  if ($("#form_article").html() === "") {
                      $("#form_article").html(say);
                  }
                  $("#form_article").click(function(){
                      if($("#form_article").html() == say){
                          $("#form_article").html("");
                      }
                  });
                  $("#page_emotion  dd").click(function(){
                      $("#form_article").html( $("#form_article").html().replace(say, '') );
                  });
              });
          </script>

      </div>

  </footer>



        <div class="loginWrap"></div>
<div class="tipMesWrap"></div>
<div class="setting-expression-layer" style='display: none;'>
    <div class="expression" id="expressions" style="left: 26px;
    bottom: 62px;" id="expressions">
        <table class="expr-tab expr-tab1">
        </table>
    </div>
</div>




            <script>OnInit();</script>



</body>

</html>
